#!/usr/bin/env bash

set -e -u -x
source ./tasks/helpers.sh

fluent_bit_version="3.1.3"
fluent_bit_hash="4c745066223811047e3911c19db118eadec579ca62ef833a1b1fb573acd8cb85"

task_working_dir
download "https://github.com/fluent/fluent-bit/archive/refs/tags/v${fluent_bit_version}.tar.gz" "sha256" "$fluent_bit_hash"
extract_download "fb0a7a286c-v${fluent_bit_version}.tar.gz"

cd "fluent-bit-${fluent_bit_version}/build"

cmake \
  -DCMAKE_INSTALL_PREFIX="$INSTALL_PREFIX_EMBEDDED" \
  -DFLB_CUSTOM_CALYPTIA="Off" \
  -DFLB_EXAMPLES="Off" \
  -DFLB_HTTP_SERVER="On" \
  -DFLB_JEMALLOC="On" \
  -DFLB_LUAJIT="Off" \
  -DFLB_PROXY_GO="Off" \
  -DFLB_RECORD_ACCESSOR="On" \
  -DFLB_RELEASE="On" \
  -DFLB_STREAM_PROCESSOR="Off" \
  -DFLB_WASM="Off" \
  -DFLB_WINDOWS_DEFAULTS="Off" \
  -DFLB_FILTER_ALTER_SIZE="Off" \
  -DFLB_FILTER_AWS="Off" \
  -DFLB_FILTER_CHECKLIST="Off" \
  -DFLB_FILTER_ECS="Off" \
  -DFLB_FILTER_EXPECT="Off" \
  -DFLB_FILTER_GEOIP2="Off" \
  -DFLB_FILTER_GREP="Off" \
  -DFLB_FILTER_KUBERNETES="Off" \
  -DFLB_FILTER_LOG_TO_METRICS="Off" \
  -DFLB_FILTER_LUA="Off" \
  -DFLB_FILTER_LUA_USE_MPACK="Off" \
  -DFLB_FILTER_MODIFY="On" \
  -DFLB_FILTER_MULTILINE="Off" \
  -DFLB_FILTER_NEST="Off" \
  -DFLB_FILTER_NIGHTFALL="Off" \
  -DFLB_FILTER_PARSER="Off" \
  -DFLB_FILTER_RECORD_MODIFIER="Off" \
  -DFLB_FILTER_REWRITE_TAG="On" \
  -DFLB_FILTER_STDOUT="Off" \
  -DFLB_FILTER_SYSINFO="Off" \
  -DFLB_FILTER_TENSORFLOW="Off" \
  -DFLB_FILTER_THROTTLE="Off" \
  -DFLB_FILTER_THROTTLE_SIZE="Off" \
  -DFLB_FILTER_TYPE_CONVERTER="On" \
  -DFLB_FILTER_WASM="Off" \
  -DFLB_IN_CALYPTIA_FLEET="Off" \
  -DFLB_IN_COLLECTD="Off" \
  -DFLB_IN_CPU="Off" \
  -DFLB_IN_DISK="Off" \
  -DFLB_IN_DOCKER="Off" \
  -DFLB_IN_DOCKER_EVENTS="Off" \
  -DFLB_IN_DUMMY="Off" \
  -DFLB_IN_ELASTICSEARCH="Off" \
  -DFLB_IN_EMITTER="On" \
  -DFLB_IN_EVENT_TEST="Off" \
  -DFLB_IN_EVENT_TYPE="Off" \
  -DFLB_IN_EXEC="Off" \
  -DFLB_IN_EXEC_WASI="Off" \
  -DFLB_IN_FLUENTBIT_METRICS="On" \
  -DFLB_IN_FORWARD="Off" \
  -DFLB_IN_HEAD="Off" \
  -DFLB_IN_HEALTH="Off" \
  -DFLB_IN_HTTP="Off" \
  -DFLB_IN_KAFKA="Off" \
  -DFLB_IN_KMSG="Off" \
  -DFLB_IN_KUBERNETES_EVENTS="Off" \
  -DFLB_IN_LIB="Off" \
  -DFLB_IN_MEM="Off" \
  -DFLB_IN_MQTT="Off" \
  -DFLB_IN_NETIF="Off" \
  -DFLB_IN_NGINX_EXPORTER_METRICS="Off" \
  -DFLB_IN_NODE_EXPORTER_METRICS="Off" \
  -DFLB_IN_OPENTELEMETRY="Off" \
  -DFLB_IN_PODMAN_METRICS="Off" \
  -DFLB_IN_PROC="Off" \
  -DFLB_IN_PROCESS_EXPORTER_METRICS="Off" \
  -DFLB_IN_PROMETHEUS_SCRAPE="Off" \
  -DFLB_IN_RANDOM="Off" \
  -DFLB_IN_SERIAL="Off" \
  -DFLB_IN_SPLUNK="Off" \
  -DFLB_IN_STATSD="Off" \
  -DFLB_IN_STDIN="Off" \
  -DFLB_IN_STORAGE_BACKLOG="On" \
  -DFLB_IN_SYSLOG="Off" \
  -DFLB_IN_SYSTEMD="Off" \
  -DFLB_IN_TAIL="On" \
  -DFLB_IN_TCP="On" \
  -DFLB_IN_THERMAL="Off" \
  -DFLB_IN_UDP="Off" \
  -DFLB_IN_UNIX_SOCKET="Off" \
  -DFLB_IN_WINDOWS_EXPORTER_METRICS="Off" \
  -DFLB_IN_WINEVTLOG="Off" \
  -DFLB_IN_WINLOG="Off" \
  -DFLB_IN_WINSTAT="Off" \
  -DFLB_OUT_AZURE="Off" \
  -DFLB_OUT_AZURE_BLOB="Off" \
  -DFLB_OUT_AZURE_KUSTO="Off" \
  -DFLB_OUT_AZURE_LOGS_INGESTION="Off" \
  -DFLB_OUT_BIGQUERY="Off" \
  -DFLB_OUT_CALYPTIA="Off" \
  -DFLB_OUT_CHRONICLE="Off" \
  -DFLB_OUT_CLOUDWATCH_LOGS="Off" \
  -DFLB_OUT_COUNTER="Off" \
  -DFLB_OUT_DATADOG="Off" \
  -DFLB_OUT_ES="Off" \
  -DFLB_OUT_EXIT="Off" \
  -DFLB_OUT_FILE="Off" \
  -DFLB_OUT_FLOWCOUNTER="Off" \
  -DFLB_OUT_FORWARD="Off" \
  -DFLB_OUT_GELF="Off" \
  -DFLB_OUT_HTTP="Off" \
  -DFLB_OUT_INFLUXDB="Off" \
  -DFLB_OUT_KAFKA="Off" \
  -DFLB_OUT_KAFKA_REST="Off" \
  -DFLB_OUT_KINESIS_FIREHOSE="Off" \
  -DFLB_OUT_KINESIS_STREAMS="Off" \
  -DFLB_OUT_LIB="Off" \
  -DFLB_OUT_LOGDNA="Off" \
  -DFLB_OUT_LOKI="Off" \
  -DFLB_OUT_NATS="Off" \
  -DFLB_OUT_NRLOGS="Off" \
  -DFLB_OUT_NULL="Off" \
  -DFLB_OUT_OPENSEARCH="On" \
  -DFLB_OUT_OPENTELEMETRY="Off" \
  -DFLB_OUT_ORACLE_LOG_ANALYTICS="Off" \
  -DFLB_OUT_PGSQL="Off" \
  -DFLB_OUT_PLOT="Off" \
  -DFLB_OUT_PROMETHEUS_EXPORTER="Off" \
  -DFLB_OUT_PROMETHEUS_REMOTE_WRITE="Off" \
  -DFLB_OUT_RETRY="Off" \
  -DFLB_OUT_S3="On" \
  -DFLB_OUT_SKYWALKING="Off" \
  -DFLB_OUT_SLACK="Off" \
  -DFLB_OUT_SPLUNK="Off" \
  -DFLB_OUT_STACKDRIVER="Off" \
  -DFLB_OUT_STDOUT="On" \
  -DFLB_OUT_SYSLOG="Off" \
  -DFLB_OUT_TCP="Off" \
  -DFLB_OUT_TD="Off" \
  -DFLB_OUT_UDP="Off" \
  -DFLB_OUT_VIVO_EXPORTER="Off" \
  -DFLB_OUT_WEBSOCKET="Off" \
  -DFLB_PROCESSOR_ATTRIBUTES="Off" \
  -DFLB_PROCESSOR_LABELS="Off" \
  ../
make -j"$NPROC"
make install DESTDIR="$STAGE_DIR"

stamp
